package com.project.template.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.project.template.common.PageVO;
import com.project.template.common.Result;
import com.project.template.entity.Link;
import com.project.template.service.LinkService;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 轮播图 前端控制器
 * </p>
 *
 *
 */
@RestController
@RequestMapping("/link")
public class LinkController {
        @Resource
        private LinkService service;
        /**
         * 列表
         */
        @GetMapping("/list")
        public Result<List<Link>>list(){
                return new Result<>().success(service.list());
                }

        /**
         * 分页查询
         */
        @GetMapping("/page")
        public Result<PageVO<Link>>findPage(@RequestParam Map<String, Object> query,@RequestParam(defaultValue = "1") Integer pageNum,@RequestParam(defaultValue = "10") Integer pageSize){
            Page<Link> page=service.page(query,pageNum,pageSize);
            return new Result<>().success(new PageVO<>(page));
        }

        /**
         * 数据新增
         */
        @PostMapping("/add")
        public Result add(@Validated @RequestBody Link entity){
                service.save(entity);
                return new Result<>().success();
        }

        /**
         * 数据更新
         */
        @PutMapping("/update")
        public Result updateById(@Validated @RequestBody Link entity){
                service.updateById(entity);
                return new Result<>().success();
        }

        /**
         * 根据id删除
         */
        @DeleteMapping("/delBatch")
        public Result delBatch(@RequestBody List<Integer> ids){
                service.removeByIds(ids);
                return new Result<>().success();
        }

        /**
         * 根据id查询
         */
        @GetMapping("/getById")
        public Result<Link> getById(@RequestParam("id") Integer id){
                Link entity=service.getById(id);
                return new Result<>().success(entity);
        }
}
